home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / bccapp.zip / UTILITY.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  5KB  |  240 lines

  1. /*
  2.  *
  3.  * Generic utility routines used throughout an applications
  4.  *
  5.  * (C) 1990 Vision Software
  6.  *
  7.  * $Id: utility.c 1.2003 91/05/06 14:25:03 pcalvin beta $
  8.  *
  9.  * Comments:
  10.  *
  11.  * Public utility functions.  Not specific to any class, this file contains
  12.  * routines that may be useful to everyone (including the General Public)
  13.  *
  14.  * Bugs:
  15.  *
  16.  * None documented
  17.  *
  18.  */
  19. #include <iostream.h>
  20. #include <dos.h>
  21. #include <string.h>
  22.  
  23. #include <stdhdr.h>
  24.  
  25. #include <adl.h>
  26. #include <menu.h>
  27. #include <batch.h>
  28. #include <dbase.h>
  29.  
  30. #include "lowlevel.h"
  31.  
  32. /*
  33.  * Company profile
  34.  */
  35. struct COMPANY : public DBASE
  36.     {
  37.     CHAR szCompany[25];
  38.     CHAR szAddress1[25];
  39.     CHAR szAddress2[25];
  40.     CHAR szAddress3[25];
  41.     CHAR szPhone[10];
  42.     CHAR szZip[6];
  43.     };
  44.  
  45. COMPANY cmp;
  46. /*
  47.  * Functions used by standard menu entry
  48.  */
  49. STATIC VOID EditCompany();
  50.  
  51. /*
  52.  * Standard menu item.  Usually the first entry under the "System" title
  53.  */
  54. ENT pentVision[] = {
  55.     { "Vision Software",0,Propaganda,"Display Vision Software Company Information" },
  56.     { "Company Profile",0,EditCompany,"Maintain Company Profile" },
  57.     { "DOS Shell",0,DosShell,"Spawn a DOS Shell",},
  58.     { "Exit to DOS",0,TerminateApplication,"Terminate Program, Return to DOS" },
  59.     };
  60.  
  61. /*
  62.  * Standard Dialogs Buttons
  63.  */
  64. STATIC ENT pentYesNo[] = {
  65.     { "Yes",0,0,0 },
  66.     { "No",0,0,0 }
  67.     };
  68.  
  69. /*
  70.  * Vision Propaganda
  71.  */
  72. EXTERN VOID Propaganda()
  73.     {
  74.     STATIC CONST SZ szProceed = " Proceed ";
  75.     WINDOW wnd(5,15,14,65,coBlack,coCyan);
  76.     CURSOR crs(fFalse);
  77.     HELP help(szNil);
  78.  
  79.     wnd.Open();
  80.  
  81.     wnd.SayCentered(1,"C++ Applications Development Library");
  82.     wnd.SayCentered(3,"(C)1991 Vision Software (Canada)",coDarkGray);
  83.     wnd.SayCentered(4,"Written by Phil Calvin",coDarkGray);
  84.     wnd.SayCentered(5,"(416) 335-8345",coDarkGray);
  85.     wnd.SayCentered(7,szProceed,coBlack,coGreen);
  86.  
  87.     help.Replace("Press <ENTER> to continue application");
  88.  
  89.     /*
  90.      * Wait specifically for the enter key
  91.      */
  92.     while (CdInput() != cdReturn)
  93.         ;
  94.  
  95.     /*
  96.      * Simulate the flash of "Normal" popups..
  97.      */
  98.     for (INT count=0; count < 5; count++)
  99.         {
  100.         wnd.SayCentered(7,szProceed,coBlack,coCyan);
  101.         delay(40);
  102.         wnd.SayCentered(7,szProceed,coBlack,coGreen);
  103.         delay(40);
  104.         }
  105.  
  106.     wnd.Close();
  107.     }
  108.  
  109. /*
  110.  * Opens a dialog, Answers with user result
  111.  */
  112. EXTERN BOOL FAskSz(SZ sz,SZ szHelp)
  113.     {
  114.     DIALOG dial(sz,2,pentYesNo);
  115.  
  116.     /*
  117.      * Provide QuickHelp if desired.
  118.      */
  119.     pentYesNo[0].szQuickHelp = szHelp;
  120.     pentYesNo[1].szQuickHelp = szHelp;
  121.  
  122.     return (!dial.CentGet());
  123.     }
  124.  
  125. /*
  126.  *    Opens a dialog.  Simple Message to user
  127.  *
  128.  *    NOTE: Double braces around OK are needed so compiler
  129.  *            does not whine.
  130.  */
  131. EXTERN VOID SaySz(SZ sz,SZ szHelp)
  132.     {
  133.     STATIC ENT pent[] = { { " Ok " } };
  134.     DIALOG dial(sz,1,pent);
  135.  
  136.     /*
  137.      * Place the QuickHelp..
  138.      */
  139.     pent->szQuickHelp = szHelp;
  140.  
  141.     /*
  142.      *    No response needed..
  143.      */
  144.     (VOID)dial.CentGet();
  145.     }
  146.  
  147. /*
  148.  *    Opens a dialog.  Error message to the user
  149.  *
  150.  *    NOTE: Double braces around Error are needed so compiler
  151.  *            does not whine.
  152.  */
  153. EXTERN VOID ErrorSz(SZ sz,SZ szHelp)
  154.     {
  155.     STATIC ENT pent[] = { { " Error " } };
  156.     DIALOG dial(sz,1,pent);
  157.  
  158.     /*
  159.      * Place the QuickHelp..
  160.      */
  161.     pent->szQuickHelp = szHelp;
  162.  
  163.     /*
  164.      *    No response needed..
  165.      */
  166.     (VOID)dial.CentGet();
  167.     }
  168.     
  169. /*
  170.  * Answers with a <TEMPORARY> string that is left aligned and padded
  171.  * with spaces
  172.  */
  173. EXTERN SZ SzTempPaddedFromSzCch(SZ szSource,CCH cchMax)
  174.     {
  175.     PointerAssert(szSource);
  176.     Assert(cchMax < cchSzTempMax);
  177.  
  178.     STATIC SZTEMP sz;
  179.     SZ szWork = sz;
  180.  
  181.     /*
  182.      * Answers with a left aligned string padded with spaces.
  183.      */
  184.     for (CCH cch = 0; cch < cchMax; cch++)
  185.         {
  186.         if (*szSource != chNil)
  187.             *szWork++ = *szSource++;
  188.         else
  189.             *szWork++ = chSpace;
  190.         }
  191.  
  192.     *szWork = chNil;
  193.  
  194.     return (sz);
  195.     }
  196.  
  197. /* 
  198.  *    Answers with the maximum width of the entries within
  199.  *    the ENT
  200.  */
  201. EXTERN CCH CchFromCentPent(CENT centMac,PENT pentBase)
  202.     {
  203.     Assert(pentBase != pentNil);
  204.     
  205.     REGISTER PENT pent = pentBase;
  206.     REGISTER CENT cent = centNil;
  207.     REGISTER CCH cch = cchNil;
  208.  
  209.     /*
  210.      *    Loop over all..
  211.      */
  212.     while (cent < centMac)
  213.         {
  214.         Assert(pent->sz != szNil);
  215.  
  216.         cch = Max(cch,strlen(pent->sz));
  217.  
  218.         pent++;
  219.         cent++;
  220.         }
  221.  
  222.     return (cch);
  223.     }
  224.  
  225.  
  226. STATIC VOID EditCompany()
  227.     {
  228.     DATABASE dtb(&cmp,sizeof(cmp),"company",fTrue);
  229.     BATCH bth(dtb,"Edit Company Profile");
  230.  
  231.     bth.Field(1,1,"Company Name :",cmp.szCompany,'X',25,"Enter the company's full name");
  232.     bth.Field(3,1,"Address      :",cmp.szAddress1,'X',25,"Enter the company's full address");
  233.     bth.Field(4,1,"City         :",cmp.szAddress2,'X',25,"Enter the company's full address");
  234.     bth.Field(5,1,"Province     :",cmp.szAddress3,'X',25,"Enter the company's full address");
  235.     bth.Field(7,1,"Phone Number :",cmp.szPhone,'9',10,"Enter the company's phone number");
  236.     bth.Field(8,1,"Postal Code  :",cmp.szZip,"U9U9U9","Enter the company's postal code");
  237.  
  238.     bth.Read();
  239.     }
  240.